package com.example.user.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.dtos.ResponseResult;
import com.example.user.entity.User;
import com.example.user.service.IUserService;
import com.example.utils.RegexUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 凡哥哥
 * @since 2023-10-16
 */
@RestController
@RequestMapping("/user")
@Slf4j
@Api(tags = "用户端控制器")
@CrossOrigin
public class UserController {
    @Autowired
    private IUserService userService;
    /*登录*/
    @ApiOperation(value = "登录")
    @GetMapping
    public ResponseResult<User> login(@RequestBody User user){

        return userService.login(user);
    }

    /**
     * 查询用户信息
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @ApiOperation(value = "查询用户信息")
    @GetMapping("/page")
    public ResponseResult<Page> page(Integer page, Integer pageSize, String name) {

        return userService.pageInfo(page, pageSize, name);
    }

    /**
     * 修改状态
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改状态")
    @PutMapping("/status")
    public ResponseResult status(Long id) {

        return ResponseResult.okResult(userService.updateStatus(id));
    }

    /**
     * 发送验证码
     * @param phone
     * @return
     */
    @ApiOperation(value = "发送验证码")
    @GetMapping("/code")
    public ResponseResult<String> sendCode(String phone) {
        return userService.sendCode(phone);
    }

    /*注册*/
    @ApiOperation(value = "注册")
    @PostMapping("/register")
    public ResponseResult<String> register(@RequestBody User user){
        return userService.register(user);
    }

    /**
     * 用户退出
     */
    @ApiOperation(value = "用户退出")
    @GetMapping("/logout")
    public ResponseResult<String> logout(String token){
        userService.exit(token);
        return ResponseResult.okResult("退出成功");
    }
    /**
     * 用户点赞状态
     */
    /*@GetMapping("/likes/{userId}")
    public R<List<Likes>> likes(@PathVariable Long userId){
        //获取点赞状态
        if (userId != null){
            return R.success(userService.likes(userId));
        }
        return R.error("用户未登录");
    }*/
    /**
     * 删除
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除")
    @DeleteMapping
    public ResponseResult delete(int [] ids) {
        return userService.deleteUsers(ids);
    }
}

